package com.example.qxfw.nyqx.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.nyqx.mapper.CropGrowdateHistoryMapper;
import com.example.qxfw.nyqx.service.CropGrowdateHistoryService;
import com.example.qxfw.nyqx.vo.GrowdateHistoryListVo;
import com.example.qxfw.common.entity.ny.CropGrowdateHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CropGrowdateHistoryServiceImpl implements CropGrowdateHistoryService {

    @Autowired
    private CropGrowdateHistoryMapper cropGrowdateHistoryMapper;

    @Override
    public List<GrowdateHistoryListVo> getList(long year1, long year2, String stationId, String type, String cropName, String growDateName) {
        return cropGrowdateHistoryMapper.selectList1(year1, year2, stationId, type, cropName, growDateName);
    }

    @Override
    public List<CropGrowdateHistory> getList1(long year, String stationId, String type, String cropName) {
        return cropGrowdateHistoryMapper.selectList(Wrappers.<CropGrowdateHistory>lambdaQuery()
                .eq(CropGrowdateHistory::getYear,year)
                .eq(CropGrowdateHistory::getStationid,stationId)
                .eq(CropGrowdateHistory::getType,type)
                .eq(CropGrowdateHistory::getCropname,cropName));
    }

    @Override
    public List<CropGrowdateHistory> getList2(long year1, long year2, String stationId, String type, String cropName, String growName) {
        return cropGrowdateHistoryMapper.selectList(Wrappers.<CropGrowdateHistory>lambdaQuery()
                .ge(CropGrowdateHistory::getYear,year1)
                .le(CropGrowdateHistory::getYear,year2)
                .eq(CropGrowdateHistory::getStationid,stationId)
                .eq(CropGrowdateHistory::getType,type)
                .eq(CropGrowdateHistory::getCropname,cropName)
                .eq(!growName.equals("全部发育期"),CropGrowdateHistory::getGrowdatename,growName)
                .orderByAsc(CropGrowdateHistory::getGrowdatedate));
    }

}
